﻿Public Class NguoiThueNhaDAO

    Private connect As ConnectDB
    Private sqlstr As String


    Public Sub New()
        connect = New ConnectDB()
    End Sub

    Public Function IsUpNT(ByVal emp As NguoiThueNhaDTO, ByVal flag As Boolean)
        Dim Ma As String = emp.Mã_người_thuê
        Dim Hoten As String = emp.Họ_tên
        Dim Email As String = emp.Email
        Dim Nghenghiep As String = emp.Nghê_nghiệp
        Dim SoCMND As String = emp.Số_CMND
        Dim Dienthoai As String = emp.Điện_Thoại
        Dim MaKV As String = emp.Mã_Khu_Vực
        Dim MaLN As String = emp.Mã_loại_nhà
        '-------------------------------------------'
        If flag = True Then
            sqlstr = "INSERT NGUOITHUE (HoTenNT, EmailNT, NgheNghiep, SoCMND, DienThoaiNT, MaKhuVuc, MaLoaiNha)" & _
                        " VALUES('" & Hoten & "', '" & Email & "', '" & _
                                     Nghenghiep & "', '" & SoCMND & "', '" & _
                                        Dienthoai & "', '" & MaKV & "', '" & MaLN & "')"
        Else
            sqlstr = "UPDATE NGUOITHUE SET  HoTenNT  = '" & Hoten & _
                                        "', EmailNT   = '" & Email & _
                                        "', NgheNghiep     = '" & Nghenghiep & _
                                        "',  SoCMND      = '" & SoCMND & _
                                        "', DienThoaiNT   = '" & Dienthoai & _
                                        "', MaKhuVuc      = '" & MaKV & _
                                        "',  MaLoaiNha      = '" & MaLN & _
                                    "' WHERE MaNguoiThue  = '" & Ma & "'"

        End If
        Return connect.Execute(sqlstr)
    End Function

    Public Function DeleteNT(ByVal emp As NguoiThueNhaDTO)
        Dim EmpID As String = emp.Mã_người_thuê
        sqlstr = "DELETE NGUOITHUE WHERE MaNguoiThue = '" & EmpID & "'"
        Return connect.Execute(sqlstr)
    End Function

    Public Function Getdata() As List(Of NguoiThueNhaDTO)
        Dim i As Integer
        Dim id, pw, ht, ns, gt, dc, sdt, lnv As String
        Dim emp As NguoiThueNhaDTO
        Dim empLst As New List(Of NguoiThueNhaDTO)
        Dim dt As New DataTable
        dt = connect.GetData("Select * From NGUOITHUE")

        For i = 0 To dt.Rows.Count() - 1
            id = dt.Rows(i)("MaNguoiThue").ToString
            pw = dt.Rows(i)("HoTenNT").ToString
            ht = dt.Rows(i)("EmailNT").ToString
            ns = dt.Rows(i)("NgheNghiep").ToString
            gt = dt.Rows(i)("SoCMND").ToString
            dc = dt.Rows(i)("DienThoaiNT").ToString
            sdt = dt.Rows(i)("MaKhuVuc").ToString
            lnv = dt.Rows(i)("MaLoaiNha").ToString
            emp = New NguoiThueNhaDTO(id, pw, ht, ns, gt, dc, sdt, lnv)
            empLst.Add(emp)
        Next
        Return empLst
    End Function

    


End Class
